package com.binc.testspring.study.jdkObjservable;

import java.util.Observable;
import java.util.Observer;


public class Teacher implements Observer {

    private String name;

    public Teacher(String name) {
        this.name = name;
    }



    public void update(Observable o, Object arg) {
        Gper gper = (Gper)o;
        Question question = (Question)arg;
        System.out.println("======================");
        System.out.println(name + "老师，你好！\n" +
                "您收到了一个来自" + gper.getName() + "的提问，希望您解答。问题内容如下：\n" +
                question.getContent() + "\n" + "提问者：" + question.getUserName());
    }




    //////////////////////////////////////////////////////
    public static void main(String[] args) {
        Gper gper = Gper.getInstance();
        Teacher tom = new Teacher("Tom");
        Teacher jerry = new Teacher("Jerry");

        gper.addObserver(tom);
        gper.addObserver(jerry);

        //用户行为
        Question question = new Question();
        question.setUserName("张三");
        question.setContent("观察者模式适用于哪些场景？");

        gper.publishQuestion(question);
    }


}